VERSION=$(git describe --tags)
BUILD=$(date +%FT%T%z)
GIT_COMMIT=$(git rev-list -1 HEAD)
APPVERSION=${VERSION}
APPBUILDTIME=${BUILD}
APPCOMMIT=${GIT_COMMIT}

echo "Version: ${APPVERSION}"
echo "Build: ${APPCOMMIT}--${APPBUILDTIME}"

if [ ! -d "${DISTPATH}" ]; then
    echo "Directory ${DISTPATH} DOES NOT exist."
    if [ -d "$1" ]; then
        DISTPATH="$1"
        echo "DISTPATH is set to $1"
    else
        echo "Directory $1 also DOES NOT exist. Exiting."
        exit
    fi
else
    echo "yes"
fi

LDFlags="
    -s -w
    -X 'github.com/xuelang-group/suanpan-appconnector/cmd/appconnector/global.Version=${APPVERSION}' \
    -X 'github.com/xuelang-group/suanpan-appconnector/cmd/appconnector/global.Build=${APPCOMMIT}--${APPBUILDTIME}' \
    -X 'github.com/xuelang-group/suanpan-appconnector/cmd/appconnector/global.Type=tiny' \
"

#go build -v -ldflags="-X main.Version=${APPVERSION} -X main.Build=${APPCOMMIT}--${APPBUILDTIME} -X main.Type=full" main.go
CGO_ENABLED=0 go build -v -ldflags="$LDFlags" -o $DISTPATH/connectgo cmd/appconnector/main.go
#/usr/local/go/bin/go build -ldflags="-s -w" -o test_no_debug_and_symbol_upx9_compress main.go && upx -9 test_no_debug_and_symbol_upx9_compress
